-- @owner: opentestcase013
-- @date: 2023/7/31
-- @testpoint: 普通非压缩表，修改compresstype=1, compress_byte_convert不同取值，部分合理报错
-- modified by opentestcase013 at 2023/9/26:增加checkpoint步骤

--step1:建普通表并插入数据;expect:成功
drop table if exists t_alter_rowcompress_0009;
create table t_alter_rowcompress_0009(id int, c1 text);
insert into t_alter_rowcompress_0009 select generate_series(1, 1000), 'testrowcompress';

drop function if exists compress_func_findpath(character varying);
create or replace function compress_func_findpath(character varying)
returns character varying
language plpgsql
as
$body$
declare
relpath character varying;
begin
relpath = (select pg_relation_filepath(relname::regclass) from pg_class where relname = $1);
return relpath;
end;
$body$;
/

--step2:修改压缩参数compresstype=1,compress_byte_convert=true;expect:成功
alter table t_alter_rowcompress_0009 set (compresstype=1,compress_byte_convert=true);
checkpoint;
select is_compress, file_count, logic_size, physic_size, compress_ratio from pg_catalog.compress_ratio_info(compress_func_findpath('t_alter_rowcompress_0009'));
select chunk_size, algorithm from pg_catalog.compress_address_header('t_alter_rowcompress_0009', 0);

--step3:修改压缩参数compresstype=1,compress_byte_convert=false;expect:成功
alter table t_alter_rowcompress_0009 set (compresstype=1,compress_byte_convert=false);
checkpoint;
select is_compress, file_count, logic_size, physic_size, compress_ratio from pg_catalog.compress_ratio_info(compress_func_findpath('t_alter_rowcompress_0009'));
select chunk_size, algorithm from pg_catalog.compress_address_header('t_alter_rowcompress_0009', 0);

--step4:修改压缩参数compresstype=1,compress_byte_convert为无效值;expect:合理报错
alter table t_alter_rowcompress_0009 set (compresstype=1,compress_byte_convert='test');
alter table t_alter_rowcompress_0009 set (compresstype=1,compress_byte_convert=2.2);

--step5:清理环境;expect:成功
drop table if exists t_alter_rowcompress_0009;
drop function if exists compress_func_findpath(character varying);